package easy;

public class Solution_925 {

    public boolean isLongPressedName(String name, String typed) {
        if (name.length() > typed.length()) {
            return false;
        }
        char[] names = name.toCharArray();
        char[] typeds = typed.toCharArray();
        int type_index = 0;
        for (int i = 0, count = 0; i <= names.length; i++) {
            if (count == 0) {
                count = 1;
                continue;
            }
            if (i < names.length && names[i] == names[i - 1]) {
                count++;
            } else {
                int type_count = 0;
                for (; type_index < typeds.length; type_index++) {
                    if (typeds[type_index] == names[i - 1]) {
                        type_count++;
                    } else {
                        break;
                    }
                }
                if (type_count < count) {
                    return false;
                }
                count = 1;
            }
        }
        while (type_index < typeds.length) {
            if (typeds[type_index] != typeds[type_index - 1]) {
                return false;
            }
            type_index++;
        }
        return true;
    }

    public static void main(String[] args) {
        Solution_925 model = new Solution_925();
        System.out.println(model.isLongPressedName("rick", "kric"));
        System.out.println(model.isLongPressedName("alex", "aaleex"));
        System.out.println(model.isLongPressedName("saeed", "ssaaedd"));
        System.out.println(model.isLongPressedName("leelee", "lleeelee"));
        System.out.println(model.isLongPressedName("laiden", "laiden"));
        System.out.println(model.isLongPressedName("a", "b"));
        System.out.println(model.isLongPressedName("alex", "aaleexa"));
    }
}
